package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.labillusion.core.util.StringUtils;
import com.labillusion.core.util.UUIDUtils;
import com.ujoku.dao.SeoDao;
import com.ujoku.domain.Seo;
import com.ujoku.service.SeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2015/5/6.
 */
@Service
public class SeoServiceImpl extends BaseServiceImpl<Seo> implements SeoService<Seo> {
    @Autowired
    private SeoDao dao;

    /**
     * 获取基础数据库操作类
     *
     * @return
     */
    @Override
    protected BaseDao<Seo> getBaseDao() {
        return dao;
    }

    @Override
    public Seo selectByUrl(String url) {
        if(!StringUtils.hasText(url))
            return null;

        if(url.contains("/p/"))
            url = "/p/";

        List<Seo> seoList = this.selectList();

        final String finalUrl = url;
        Seo seo = seoList.stream().filter(s-> finalUrl.equalsIgnoreCase(s.getUrl())).findFirst().orElse(null);

        return seo;
    }
}
